package com.zhida.smartcontrol.pagectrl.lampmanager.singlelamp;

import com.zhida.smartcontrol.common.Const;
import com.zhida.smartcontrol.common.bean.LampSwitchBean;
import com.zhida.smartcontrol.mvp.BasePresenterImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * author: tanjianpei
 * date: 2019/10/17 017 15:11
 * description:
 */
public class SingleLampPresenter extends BasePresenterImpl<SingleLampContract.View> implements SingleLampContract.Presenter {

    @Override
    public void checkData(List<LampSwitchBean> sourceList, int type) {
        int switchType = -1;
        List<LampSwitchBean> beanList = new ArrayList<>();
        for (LampSwitchBean bean : sourceList) {
            if (bean.isCheck()) {
                beanList.add(bean);
                switchType = Integer.parseInt(bean.getSwitchType());
                for (LampSwitchBean switchBean : beanList) {
                    if (!switchBean.getSwitchType().equals(bean.getSwitchType())) {
                        switchType = -2;
                        beanList.clear();
                        break;
                    }
                }
            }
            if (switchType == -2) {
                break;
            }
        }

        if (beanList.size() > 0) {
            if (switchType == Const.PLC_SINGLE && (type == 0 || type == 2 || type == 4)) {
                mView.showMsg("PLC单灯不支持该模式设置");
                return;
            }
            mView.checkDataOk(type, switchType, beanList);
        } else {
            if (switchType != -2) {
                mView.showMsg("请选择要操作的单灯");
            } else {
                mView.showMsg("所选单灯必须是同一类型");
            }
        }

    }
}
